﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;

namespace PrjAssessModels.BaseModels
{
    public class Project : BaseEntity
    {
        public Project()
        {
            MaterialBurys = new List<MaterialBuryItem>();
            Works = new List<WorkItem>();
            this.PrjExtent = new ProjectExtent();
        }
        [Required]
        [DataType(DataType.Date)]
        [Display(Name = "测算日期")]
        public DateTime AssessDate { get; set; }

        [Required]
        [Display(Name = "项目编号")]
        public string PrjId { get; set; }

        [Required]
        [Display(Name = "项目名称")]
        public string PrjName { get; set; }

        [Required]
        [Display(Name = "合同额")]
        public double Contract { get; set; }

        [Required]
        [Display(Name = "地址")]
        public string Address { get; set; }

        [Required]
        [Display(Name = "项目经理")]
        public string Manager { get; set; }

        [Required]
        [Display(Name = "班组长")]
        public string Leader { get; set; }

        [Required]
        [Display(Name = "采购厂商")]
        public string Manufacture { get; set; }

        [Required]
        [Display(Name = "监测类型")]
        public string MonitorType { get; set; }

        [Required]
        [Display(Name = "监测次数")]
        public double SurveyNo { get; set; }

        public bool FromExcel { get; set; }

        public ProjectExtent PrjExtent { get; set; }

        public List<MaterialBuryItem> MaterialBurys { get; set; }

        public List<WorkItem> Works { get; set; }


        [Display(Name = "材料埋设费用明细")]
        public List<ContentItem> ContentGroup
        {
            get
            {
                var group = from c in MaterialBurys
                            group c by c.ContentName into g
                            select new ContentItem()
                            {
                                ContentName = g.Key,
                                Items = g.ToList(),
                                
                            };
                return group.ToList();
            }
        }


       
        [Display(Name = "材料埋设总费用")]
        public  double MaterialBurySum
        {
            get
            {
                return this.MaterialSum + this.BurySum;
            }
        }


        [Display(Name = "材料总费用")]
        public  double MaterialSum
        {
            get
            {
                double material_sum = this.MaterialBurys.Sum(v => v.MaterialTotal);
                material_sum = material_sum * this.PrjExtent.MaterialPurchaseRatio;
                return material_sum;
            }
        }


        [Display(Name = "埋设总费用")]
        public  double BurySum
        {
            get
            {
                double bury_sum = this.MaterialBurys.Sum(v => v.BuryTotal);
                return bury_sum;
            }
        }



        [Display(Name = "核定工作量")]
        public double WorkSum
        {
            get
            {
                double W_sum = this.Works.Sum(p => p.Sum);
                return W_sum * this.PrjExtent.WorkRatio;
            }
        }

        [Required]
        [Display(Name = "工期")]
        public int ConstructionPeriod { get; set; }
    }
}
